import common from "../../../utils/public.js"

Page({
  data: {
    userid: 0,
    isremove: false,
    headerArray: [{
      text: '申请日期'
    },{
      text: '学号',
    }, {
      text: '姓名'
    }, {
      text: '专业'
    }, {
      text: '班级'
    }, {
      text: '手机号'
    },{
      text:'外出时间'
    },{
      text:'目的地'
    },{
      text:'外出原因'
    },{
      text:'操作'
    }],
    reportList: []
  },

  click: function(e) {
    var that = this;
    let id= e.currentTarget.dataset.id;
    let duration= e.currentTarget.dataset.duration;
    wx.request({
      url: 'http://localhost:8080/clock_war_exploded/manager/approveUserReport',
      method:'POST',
      header:{'content-type':'application/x-www-form-urlencoded;charset=utf-8'},
      data: {
        id: id,
        duration: duration,
      },
      success: function (res) {
        if (res.data){
        wx.showToast({
          title: '提交成功',
          icon:'success',
        })
        that.onShow();
        }else{
        wx.showModal({
          title: '温馨提示',
          content: '您已提交过，请不要重复提交',
        })
        }       
      }
      })
  },


    /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.onShow();
  },
  onShow: function() {
    var that = this;
    wx.request({
      url: 'http://localhost:8080/clock_war_exploded/manager/findAllReport',
      method:'POST',
      header:{'content-type':'application/x-www-form-urlencoded;charset=utf-8'},
      success: function(res) {
        if (res.data != null) {
          res.data.forEach(item=>{
            item.date=common.getMyDate(item.date)
          })
          that.setData({
            searchLoading: true, //把"上拉加载"的变量设为true，显示  
            searchLoadingComplete: false, //把“没有数据”设为false，隐藏 
            reportList: res.data
          })
        } else {
          that.setData({
            searchLoadingComplete: true, //把“没有数据”设为true，显示  
            searchLoading: false //把"上拉加载"的变量设为false，隐藏  
          })
        }
      }
    })
  }
})